package net.maku.user.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import net.maku.framework.common.utils.PageResult;
import net.maku.framework.common.utils.Result;
import net.maku.framework.operatelog.annotations.OperateLog;
import net.maku.framework.operatelog.enums.OperateTypeEnum;
import net.maku.user.service.UserInfoService;
import net.maku.user.query.UserInfoQuery;
import net.maku.user.vo.UserInfoVO;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.util.List;

/**
 * 维修信息
 *
 * @author df
 *
 */
@RestController
@RequestMapping("/user/info")
@Tag(name="维修信息")
@AllArgsConstructor
public class UserInfoController {
    private final UserInfoService userInfoService;

    @GetMapping("page")
    @Operation(summary = "分页")
    @PreAuthorize("hasAuthority('user:info')")
    public Result<PageResult<UserInfoVO>> page(@ParameterObject @Valid UserInfoQuery query){
        PageResult<UserInfoVO> page = userInfoService.page(query);

        return Result.ok(page);
    }


    @GetMapping("{id}")
    @Operation(summary = "信息")
    @PreAuthorize("hasAuthority('user:info')")
    public Result<UserInfoVO> get(@PathVariable("id") Long id){
        UserInfoVO data = userInfoService.get(id);

        return Result.ok(data);
    }

    @PostMapping("save")
    @Operation(summary = "保存")
    public Result<String> save(@RequestBody UserInfoVO vo){
        userInfoService.save(vo);

        return Result.ok();
    }


    @DeleteMapping
    @Operation(summary = "删除")
    @OperateLog(type = OperateTypeEnum.DELETE)
    @PreAuthorize("hasAuthority('user:info')")
    public Result<String> delete(@RequestBody List<Long> idList){
        userInfoService.delete(idList);

        return Result.ok();
    }


    @GetMapping("export")
    @Operation(summary = "导出")
    @OperateLog(type = OperateTypeEnum.EXPORT)
    @PreAuthorize("hasAuthority('user:info')")
    public void export() {
        userInfoService.export();
    }
}